import * as _ from 'lodash';

/**
 * camelCaseKey 对象的 Key 下划线转驼峰，深度转换
 */
export function camelCaseKey(obj: any): any {
  if (_.isArray(obj)) {
    return _.map(obj, camelCaseKey);
  }

  if (_.isObject(obj)) {
    const newObj = new Object();
    for (const key of Reflect.ownKeys(obj)) {
      newObj[_.camelCase(key as string)] = camelCaseKey(obj[key]);
    }
    return newObj;
  }
  return obj;
}
